package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaShouhouConfig;
import com.ruoyi.system.service.IJiajiaShouhouConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后原因Controller
 * 
 * @author knd
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/jiajia/shouHouConfig")
public class JiajiaShouhouConfigController extends BaseController
{
    private String prefix = "jiajia/shouHouConfig";

    @Autowired
    private IJiajiaShouhouConfigService jiajiaShouhouConfigService;

    @RequiresPermissions("jiajia:shouHouConfig:view")
    @GetMapping()
    public String shouHouConfig()
    {
        return prefix + "/shouHouConfig";
    }

    /**
     * 查询售后原因列表
     */
    @RequiresPermissions("jiajia:shouHouConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaShouhouConfig jiajiaShouhouConfig)
    {
        startPage();
        List<JiajiaShouhouConfig> list = jiajiaShouhouConfigService.selectJiajiaShouhouConfigList(jiajiaShouhouConfig);
        return getDataTable(list);
    }

    /**
     * 导出售后原因列表
     */
    @RequiresPermissions("jiajia:shouHouConfig:export")
    @Log(title = "售后原因", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaShouhouConfig jiajiaShouhouConfig)
    {
        List<JiajiaShouhouConfig> list = jiajiaShouhouConfigService.selectJiajiaShouhouConfigList(jiajiaShouhouConfig);
        ExcelUtil<JiajiaShouhouConfig> util = new ExcelUtil<JiajiaShouhouConfig>(JiajiaShouhouConfig.class);
        return util.exportExcel(list, "售后原因数据");
    }

    /**
     * 新增售后原因
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售后原因
     */
    @RequiresPermissions("jiajia:shouHouConfig:add")
    @Log(title = "售后原因", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaShouhouConfig jiajiaShouhouConfig)
    {
        return toAjax(jiajiaShouhouConfigService.insertJiajiaShouhouConfig(jiajiaShouhouConfig));
    }

    /**
     * 修改售后原因
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaShouhouConfig jiajiaShouhouConfig = jiajiaShouhouConfigService.selectJiajiaShouhouConfigById(id);
        mmap.put("jiajiaShouhouConfig", jiajiaShouhouConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存售后原因
     */
    @RequiresPermissions("jiajia:shouHouConfig:edit")
    @Log(title = "售后原因", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaShouhouConfig jiajiaShouhouConfig)
    {
        return toAjax(jiajiaShouhouConfigService.updateJiajiaShouhouConfig(jiajiaShouhouConfig));
    }

    /**
     * 删除售后原因
     */
    @RequiresPermissions("jiajia:shouHouConfig:remove")
    @Log(title = "售后原因", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaShouhouConfigService.deleteJiajiaShouhouConfigByIds(ids));
    }
}
